﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dos.Model;

public partial class webmx_program_gongde_Add : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            temple_Contents ad = new temple_Contents();
            CategoryActions ca = new CategoryActions();
            string imgname;
            try
            {
                HttpPostedFile imgFile = HttpContext.Current.Request.Files[0];
                imgname = Guid.NewGuid().ToString() + "." + imgFile.FileName.Split('.')[1];
                string savePath = Server.MapPath("~/upload/gd/" + imgname);
                imgFile.SaveAs(savePath);
            }
            catch (Exception)
            {
                Alert("请选择需要上传的图片!");
                return;
            }
            ad.Title = Request.Form["txtname"].ToString();
            ad.Photo = imgname;
            ad.Attachment = Request.Form["txtprice"].ToString();
            ad.SortID = int.Parse(Request.Form["txtsort"].ToString());
            ad.CategoryID = (int)ca.GetList("功德").Rows[0]["ID"];
            ad.AddUser = Session["manage"] != null ? (int)Session["manage"] : 999;
            DB.Context.Insert<temple_Contents>(ad);
            AlertRedirect("添加成功!", "list.aspx");
        }
    }
}